home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / testcpp / 4 / test.g < prev   
Encoding:
Text File  |  1994-09-14  |  937 b   |  45 lines  |  [TEXT/MPS ]

  1. /* This is test.g which tests a simple DLG-based scanner
  2.  * with user-defined tokens
  3.  */
  4.  
  5. /* Here, we use #tokdefs to define token types, but still let DLG do the
  6.  * lexing. ANTLR will not create a tokens.h file.
  7.  */
  8. #tokdefs "mytokens.h"
  9.  
  10. <<
  11. #include "DLGLexer.h"        /* include definition of DLGLexer.
  12.                              * This cannot be generated automatically because
  13.                              * ANTLR has no idea what you will call this file
  14.                              * with the DLG command-line options.
  15.                              */
  16.  
  17. typedef ANTLRCommonToken ANTLRToken;
  18.  
  19. main()
  20. {
  21.     ANTLRToken aToken;
  22.     DLGFileInput in(stdin);
  23.     DLGLexer scan(&in,2000);
  24.     ANTLRTokenBuffer pipe(&scan);
  25.     scan.setToken(&aToken);
  26.     Expr parser(&pipe);
  27.     parser.init();
  28.  
  29.     parser.e();
  30. }
  31. >>
  32.  
  33. #token "[\ \t\n]+"    <<skip();>>
  34.  
  35. class Expr {                /* Define a grammar class */
  36.  
  37. e    :    IDENTIFIER NUMBER "@"
  38.         <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
  39.     ;
  40.  
  41. }
  42.  
  43. #token IDENTIFIER    "[a-z]+"
  44. #token NUMBER        "[0-9]+"
  45.